﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using nyxwin.Common.Base.Utils;
using Newtonsoft.Json.Linq;

namespace nyxwin.Data.Common
{
    public class Active
    {
        public string Location { get; set; }
        public string LocationUrl { get; set; }

        public long Time { get; set; }
        internal DateTime StartTime { get; set; }

        public DateTime DisplayTime
        {
            get
            {
                if (Time == -1L)
                    throw new NyxException("Incorrect server time, or incorrect Friend class use !");

                return new DateTimeN(Time);
            }
        }

        public TimeSpan LastActivity
        {
            get
            {
                return StartTime - DisplayTime;
            }
        }

        internal static Active ParseJson(JObject jObject, DateTime startTime)
        {
            if (jObject == null)
                return null;

            Active act = new Active();

            act.Time = jObject.Value<long>("time");

            act.Location = jObject.Value<string>("location");

            if (act.Location == "hidden")
                act.Location = null;

            if(act.Location != null)
                act.LocationUrl = jObject.Value<string>("location_url");

            act.StartTime = startTime;

            return act;
        }
    }
}
